<?php
/**
 *                    _ooOoo_
 *                   o8888888o
 *                   88" . "88
 *                   (| -_- |)
 *                    O\ = /O
 *                ____/`---'\____
 *              .   ' \\| |// `.
 *               / \\||| : |||// \
 *             / _||||| -:- |||||- \
 *               | | \\\ - /// | |
 *             | \_| ''\---/'' | |
 *              \ .-\__ `-` ___/-. /
 *           ___`. .' /--.--\ `. . __
 *        ."" '< `.___\_<|>_/___.' >'"".
 *       | | : `- \`.;`\ _ /`;.`/ - ` : | |
 *         \ \ `-. \_ __\ /__ _/ .-` / /
 * ======`-.____`-.___\_____/___.-`____.-'======
 *                    `=---='
 *
 * .............................................
 *          佛祖保佑             永无BUG
 */

namespace App\Repositories;


use App\Good;
use App\Interfaces\GoodsService;

class GoodsRepository implements  GoodsService
{
    /**
     * 获取单个商品
     * @param $goods_id
     * @return mixed
     */
    public function get($goods_id){
        return Good::find($goods_id);
    }
    public function all($request)
    {
      $good=  Good::where('is_sale',0);
      switch ($request->type){
          case 'stock'://库存量
              $good=$good->orderBy('stock','desc');
              break;
          case 'created_at'://时间
              $good=$good->orderBy('created_at','desc');
              break;
          case 'cost_price':
              $good=$good->orderBy('cost_price','desc');
              break;
          default:
              break;
      }
      return $good=$good->get();
    }


}